from tkinter import *

class CanvasDemo:
	def __init__(self):
		window = Tk()
		window.title("Canvas")

		self.canvas = Canvas(window,width = 400, height = 200, bg = "white")
		self.canvas.pack()

		frame = Frame(window)
		frame.pack()
		bRectangle = Button(frame, text = "Rectangle",
							command = self.processRectangle)
		bOval = Button(frame, text = "Oval",
					   command = self.processOval)
		bArc = Button(frame, text = "Arc",
					  command = self.processArc)
		bPolygon = Button(frame, text = "Polygon",
						  command = self.processPolygon)
		bLine = Button(frame, text = "Line",
					   command = self.processLine)
		bString = Button(frame, text = "String",
						 command = self.processString)
		bClear = Button(frame, text = "Clear",
						command = self.processClear)


		bRectangle.grid(row = 1, column = 1)
		bOval.grid(row = 1, column = 2)
		bArc.grid(row = 1, column = 3)
		bPolygon.grid(row = 1, column = 4)
		bLine.grid(row = 1, column = 5)
		bString.grid(row = 1, column = 6)
		bClear.grid(row = 1, column = 7)

		window.mainloop()

	def processRectangle(self):
		self.canvas.create_rectangle(10,10,190,90, tags = "rect")
		#create the rectangle,the two top point is x(10,10) and y(190,90)

	def processOval(self):
		self.canvas.create_oval(10,10,190,90,tags = "oval", fill = "red")
		#create the Oval

	def processArc(self):
		self.canvas.create_arc(10,10,190,90,start = 0,extent = 90 ,width = 8,fill = "red", tags = "arc")
		#create the arc ,

	def processPolygon(self):
		self.canvas.create_polygon(10,10,190,90,10,90,tags = "polygon")
		#Create 3 points x, y, Z (10,10), (190,90), (10,90), connect the XYZ to form a triangle

	def processLine(self):
		self.canvas.create_line(10,10,190,90,fill = "red", tags = "line")
		self.canvas.create_line(10,90,190,10, width = 9,arrow = "last", activefill = "blue", tags = "line")
		#create two line:1.the red line is x(10,10) to y(190,90),and width = 1
						#2.the blue line is x(10,90) to y(190,10) and width = 9,add the arrow start to end
	def processString(self):
		self.canvas.create_text(60,40, text = "Hi,Welcome to python",font = "Times 10 bold underline", tags = "string")
		#create the string("Hi,Welcome to python")and add the underling

	def processClear(self):
		self.canvas.delete("rect","oval","arc","polygon","line","string")
		#this can clear the canvas



CanvasDemo()